package concurrencyPractice.chapter07;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

/**
 * @author xinya
 * @version 1.0
 * @project javacore
 * @description 7-11 通过改写interrupt方法将非标准的取消操作封装在Thread中
 * @date 2024/1/5 17:23:00
 */
public class ReaderThread extends Thread {
    private final Socket socket;
    private final InputStream in;

    public ReaderThread(Socket socket) throws IOException {
        this.socket = socket;
        this.in = socket.getInputStream();
    }


    public void interrupt() {
        try {
            socket.close();
        } catch (IOException ignored) {

        } finally {
            super.interrupt();
        }
    }

    @Override
    public void run() {
//        try {
//            byte[] buf = new Byte[BUFSZ];
//            while (true) {
//                int count = in.read(buf);
//                if (count < 0) {
//                    break;
//                } else if (count > 0) {
//                    processBuffer(buf, count)
//                }
//            }
//        } catch (IOException) {
//
//        }
    }
}
